package com.example.eurekastreamproduce;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.annotation.InboundChannelAdapter;

import java.text.SimpleDateFormat;
import java.util.Date;

@SpringBootApplication
@EnableBinding(Source.class)
public class EurekaStreamProduceApplication {

	private static Logger logger = LoggerFactory.getLogger(EurekaStreamProduceApplication.class);

	public static void main(String[] args) {
		SpringApplication.run(EurekaStreamProduceApplication.class, args);
	}

	/**
	 * @InboundChannelAdapter注解用来绑定输出的管道，进行消息推送。本案例就推送格式化的时间。
	 * @return
	 */
	@InboundChannelAdapter(value = Source.OUTPUT)
	public String timerMessageSource() {
		String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
		logger.info("publish message :"+format);
		return format;
	}
}
